<?php defined('SYSPATH') or die('No direct script access.');

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/9/28 15:39
 * Desc: 会员信息
 */
class Controller_Pc_Api_V2_Member_Info extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Member_Info
     */
    private $validation;

    /**
     * 服务
     * @var Service_Api_Member_Info
     */
    private $service;

    public function before()
    {
        parent::before();

        // 验证
        $this->validation = Request_Api_V2_Factory::create('member_info', $this->request_params);

        // 服务
        $this->service = new Service_Api_Member_Info();

        // 返回数据
        $this->result = array('status' => true, 'msg' => '操作成功', 'data' => array());
    }

    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    // 会员信息
    public function action_show()
    {
        try {
            $this->validation->show()->check();

            $this->result['data'] = $this->service->show($this->mid);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 修改密码
    public function action_reset_password()
    {
        try {
            $this->validation->reset_password()->check();

            $this->result['data'] = $this->service->reset_password($this->mid, $this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 更改会员信息
    public function action_modify()
    {
        try {
            $this->validation->modify()->check();

            $this->result['data'] = $this->service->modify($this->mid, $this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 用户统计相关
    public function action_statistic()
    {
        try {
            $this->validation->statistic()->check();

            $this->result['data'] = $this->service->statistic($this->mid);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 绑定
    public function action_bind()
    {
        try {
            $this->validation->bind()->check();

            $this->result['data'] = $this->service->bind($this->mid, $this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }


    // 实名认证
    public function action_real_name()
    {
        try {
            $this->validation->real_name()->check();

            $this->result['data'] = $this->service->real_name($this->mid, $this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    public function action_is_bind_third()
    {
        try {
            $this->result['data']['is_bind_third'] = $this->service->is_bind_third($this->mid);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    public function action_equity_detail()
    {
        try {
            $equity =  $this->service->get_equity_detail($this->mid);

            $this->result['data'] = $equity;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }
}
